package 面试.基础题.排序.选择排序;

import java.util.Arrays;

/**
 * 选择排序
 *
 * @author codex
 * @since 2021-10-03
 */
public class SelectionSort {
    public static void main(String[] args) {
        selectionSort();
    }
    
    /**
     * 基础实现
     */
    public static void selectionSort() {
        int[] arr = {5, 3, 7, 2, 1, 9, 8, 4};
        for (int i = 0; i < arr.length - 1; i++) {
            int k = i;
            for (int j = k + 1; j < arr.length; j++) {
                if (arr[k] > arr[j]) {
                    k = j;
                }
            }
            if (k != i) {
                int temp = arr[i];
                arr[i] = arr[k];
                arr[k] = temp;
            }
            System.out.println(Arrays.toString(arr));
        }
    }
}
